package com.codeforces.contest.c25;

import java.util.Iterator;
import java.util.Queue;
import java.util.Scanner;
import java.util.Vector;
import java.util.concurrent.ArrayBlockingQueue;


public class _25D {
	
	static Scanner scanner = new Scanner(System.in);
	static int N, ncom;
	static Vector<Integer>[] vects;
	static int[] com, visit;
	static int[][] mat;
	static Queue<Integer> qu = new ArrayBlockingQueue<Integer>(2000);

	public static void main(String[] args) {
		N = scanner.nextInt();
		vects = new Vector[N+1];
		mat = new int[N+1][N+1];
		for (int i=1;i<=N;++i) {
			vects[i] = new Vector<Integer>();
		}
		for (int i=1;i<=N-1;++i) {
			int fr, to;
			fr = scanner.nextInt();
			to = scanner.nextInt();
			vects[fr].add(to);
			vects[to].add(fr);
			mat[fr][to] = mat[fr][to] = 1;
		}
		com = new int[2000];
		visit = new int[N+1];
		ncom = 0;
		for (int i=1;i<=N;++i) {
			if (visit[i] == 0) {
				ncom++;
				visit[i] = ncom;
				com[ncom] = i;
				dfs(i,0);
			}
		}

		if (ncom == 1) {
			System.out.println(0);
		}
		else {
			System.out.println(ncom-1);
			for (int i=2;i<=ncom;++i) {
				System.out.println(qu.poll() + " " + qu.poll() + " " + com[1] + " " + com[i]);
			}
		}
	}

	private static void dfs(int i, int parent) {
		Iterator<Integer> it = vects[i].iterator();
		while (it.hasNext()) {
			int next = it.next();
			if (next == parent) {
				continue;
			}
			if (visit[next] == 0) {
				visit[next] = ncom;
				dfs(next, i);
			}
			else {
				if (mat[i][next] == 1) {
					qu.add(i);
					qu.add(next);
					mat[i][next] = mat[next][i] = 0;
				}
			}
		}
		
	}

}
